import { initPreferences } from '@vben/preferences';
import { unmountGlobalLoading } from '@vben/utils';

import {
  accordionDefinition,
  accordionItemDefinition,
  AvatarDefinition,
  ButtonDefinition,
  CheckboxDefinition,
  DialogBodyDefinition,
  DialogDefinition,
  DividerDefinition,
  DrawerBodyDefinition,
  DrawerDefinition,
  DropdownDefinition,
  DropdownOptionDefinition,
  FieldDefinition,
  FluentDesignSystem,
  ImageDefinition,
  LabelDefinition,
  LinkDefinition,
  ListboxDefinition,
  MenuButtonDefinition,
  MenuDefinition,
  MenuItemDefinition,
  MenuListDefinition,
  ProgressBarDefinition,
  RadioDefinition,
  RadioGroupDefinition,
  SliderDefinition,
  SpinnerDefinition,
  SwitchDefinition,
  TabDefinition,
  TablistDefinition,
  TabPanelDefinition,
  TextAreaDefinition,
  TextInputDefinition,
  ToggleButtonDefinition,
  TooltipDefinition,
  TreeDefinition,
  TreeItemDefinition,
} from '@fluentui/web-components';

import { overridesPreferences } from './preferences';

// Register all FluentUI components
accordionDefinition.define(FluentDesignSystem.registry);
accordionItemDefinition.define(FluentDesignSystem.registry);
DrawerBodyDefinition.define(FluentDesignSystem.registry);
DrawerDefinition.define(FluentDesignSystem.registry);
ImageDefinition.define(FluentDesignSystem.registry);
DialogDefinition.define(FluentDesignSystem.registry);
DialogBodyDefinition.define(FluentDesignSystem.registry);
RadioDefinition.define(FluentDesignSystem.registry);
RadioGroupDefinition.define(FluentDesignSystem.registry);
TabDefinition.define(FluentDesignSystem.registry);
TabPanelDefinition.define(FluentDesignSystem.registry);
TablistDefinition.define(FluentDesignSystem.registry);
TreeDefinition.define(FluentDesignSystem.registry);
TreeItemDefinition.define(FluentDesignSystem.registry);
SliderDefinition.define(FluentDesignSystem.registry);
LabelDefinition.define(FluentDesignSystem.registry);
FieldDefinition.define(FluentDesignSystem.registry);
ProgressBarDefinition.define(FluentDesignSystem.registry);
LinkDefinition.define(FluentDesignSystem.registry);
ListboxDefinition.define(FluentDesignSystem.registry);
DividerDefinition.define(FluentDesignSystem.registry);
DropdownOptionDefinition.define(FluentDesignSystem.registry);
DropdownDefinition.define(FluentDesignSystem.registry);
TextInputDefinition.define(FluentDesignSystem.registry);
ButtonDefinition.define(FluentDesignSystem.registry);
AvatarDefinition.define(FluentDesignSystem.registry);
CheckboxDefinition.define(FluentDesignSystem.registry);
MenuDefinition.define(FluentDesignSystem.registry);
MenuButtonDefinition.define(FluentDesignSystem.registry);
MenuItemDefinition.define(FluentDesignSystem.registry);
MenuListDefinition.define(FluentDesignSystem.registry);
SpinnerDefinition.define(FluentDesignSystem.registry);
SwitchDefinition.define(FluentDesignSystem.registry);
TextAreaDefinition.define(FluentDesignSystem.registry);
ToggleButtonDefinition.define(FluentDesignSystem.registry);
TooltipDefinition.define(FluentDesignSystem.registry);

/**
 * 应用初始化完成之后再进行页面加载渲染
 */
async function initApplication() {
  // name用于指定项目唯一标识
  // 用于区分不同项目的偏好设置以及存储数据的key前缀以及其他一些需要隔离的数据
  const env = import.meta.env.PROD ? 'prod' : 'dev';
  const appVersion = import.meta.env.VITE_APP_VERSION;
  const namespace = `${import.meta.env.VITE_APP_NAMESPACE}-${appVersion}-${env}`;

  // app偏好设置初始化
  await initPreferences({
    namespace,
    overrides: overridesPreferences,
  });

  // 启动应用并挂载
  // vue应用主要逻辑及视图
  const { bootstrap } = await import('./bootstrap');
  await bootstrap(namespace);

  // 移除并销毁loading
  unmountGlobalLoading();
}

initApplication();
